package com.mocoop.plugin.prompt;


import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaArgs;
import org.json.JSONArray;
import org.json.JSONException;

import com.mocoop.plugin.MocoopPlugin;
import com.mocoop.ui.ActionSheet;
import com.mocoop.ui.ActionSheet.ActionSheetListener;




public class MyActionSheet extends MocoopPlugin {
	@Override
	public boolean execute(String action, CordovaArgs args,
		final CallbackContext callbackContext) throws JSONException {
		JSONArray jarr = args.getJSONArray(1);
		final String [] strs  = new String[jarr.length()];
		for(int i=0;i<jarr.length();i++){
			strs[i] = jarr.getString(i);
		}
		
		
		ActionSheet.createBuilder(getActivity(), getActivity().getFragmentManager())
        .setCancelButtonTitle(args.getString(0))
        .setOtherButtonTitles(strs)
        .setCancelableOnTouchOutside(true)
        .setListener(new ActionSheetListener() {
			
			@Override
			public void onOtherButtonClick(ActionSheet actionSheet, int index) {
				callbackContext.success(strs[index]);
			}
			
			@Override
			public void onDismiss(ActionSheet actionSheet, boolean isCancel) {
			
			}
		}).show();
	
		return true;
	}
}
